using System;
using System.Text;
using System.ComponentModel;


namespace Grr {

	public class TaintedStringConverter : TypeConverter {

		public TaintedStringConverter()
		{
		}

		public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
		{
			if (sourceType == typeof(string))
				return true;
			return base.CanConvertFrom(context, sourceType);
		}

		public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
		{
			string strvalue = value as string;
			if (strvalue != null)
				return ConvertFromStringInternal (strvalue);
			return base.ConvertFrom(context, culture, value);
		}

		private TaintedString ConvertFromStringInternal (string str)
		{
			// Because mod_mono+xsp wants us to have index files.
			if (str == "index.aspx")
				str = String.Empty;
			return new TaintedString(str);
		}
	}
}

